<template>
  <div class="box">
    {{ 1 + 1 }}
  </div>
  <div>
    <input type="text" v-model="year" />
  </div>
  <div>
    <button @click="add">添加</button>
  </div>
</template>
<script>
import moment from 'moment'
export default {
  data() {
    return {
      a: 1,
      b: 2,
      year: 2024
    }
  },
  methods: {
    add() {
      console.log(`helloworld`)
      let now = new Date(this.year, 0, 1)
      //创造
      //看第一天是星期几
      let year_first_day = now.getDay()
      //找出所有的星期五日期
      let weeks = Math.floor(365 / 7)
      let addDate = 0
      if (year_first_day <= 5) {
        addDate = 5 - year_first_day
      } else {
        addDate = 7 + (5 - year_first_day)
      }
      //第一个星期五的日期
      now.setDate(addDate + 1)
      let format = moment(now).format('YYYY-MM-DD')
      //console.log(format)
      //console.log(year_first_day)

      for (var i = 0; i < weeks; i++) {
        //moment方法
        //let add7Date = moment(now).add(i * 7, 'd')
        //let nowDate = add7Date.date()
        //if (nowDate == 13) {
        //console.log(add7Date.format('YYYY-MM-DD'), add7Date.date())
        //}

        //原生方法
        let add7Date = new Date(this.year, 0, addDate + 1 + i * 7)
        let nowDate = add7Date.getDate()
        if (nowDate == 13) {
          console.log(moment(add7Date).format('YYYY-MM-DD'))
        }
      }
    }
  }
}
</script>
<style type="text/css">
.box {
  width: 100px;
  height: 100px;
  border: 1px solid #000;
}
</style>
